package src.lab03.test04;

import java.io.*;

/**
 * Created by Administrator on 2017/12/14.
 */
public class Test01 {
    public static void main(String[] args) {
        //1.先读文件
        String source = "D:\\hello.txt";
        String target = "E:\\hello.txt";

        //使用字节流的方式来读写文件
        //读一次写一次
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;

        try {
            fileInputStream = new FileInputStream(new File(source));
            fileOutputStream = new FileOutputStream(new File(target));

            int data;
            while ((data = fileInputStream.read()) != -1) {
                System.out.println("正在写入文件......");
                fileOutputStream.write(data);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            fileInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
